using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.XR;

namespace SunshineFarmWord
{
    public class PlayerIdlingState : PlayerBaseStates
    {
        public PlayerIdlingState(PlayerStateMachine playerStateMachine) : base(playerStateMachine)
        {
        }

        #region base function
        public override void Enter()
        {
            base.Enter();
            InitReusableData();

            StartAnimation(stateMachine.Player.AnimationData.IdleParameterHash);

            if (IsMoving())
            {
                stateMachine.ChangeState(stateMachine.WalkState);
            }
        }

        public override void Exit()
        {
            base.Exit();

            StopAnimation(stateMachine.Player.AnimationData.IdleParameterHash);
        }
        #endregion

        #region Main function

        // 初始化数据
        private void InitReusableData()
        {
            stateMachine.ReusableData.IsWalkState = false;
            stateMachine.ReusableData.IsRunState = false;
        }
        #endregion

        #region 输入回调
        // 取消移动
        protected override void OnMovementCanceled(InputAction.CallbackContext context)
        {
            base.OnMovementCanceled(context);
            //Debug.Log("取消移动-----");
        }

        // 移动中
        protected override void OnMovementPerformed(InputAction.CallbackContext context)
        {
            base.OnMovementPerformed(context);
            //Debug.Log("移动-----");
        }

        // 开始移动
        protected override void OnMovementStarted(InputAction.CallbackContext context)
        {
            base.OnMovementStarted(context);
            //Debug.Log("开始移动-----");
            stateMachine.ChangeState(stateMachine.WalkState);
        }

        // 交互
        protected override void OnInteractStarted(InputAction.CallbackContext context)
        {
            base.OnInteractStarted(context);

            if (stateMachine.ReusableData.CollisionNode != null)
            {
                GameObject collisionObj = stateMachine.ReusableData.CollisionNode;
                if (collisionObj.TryGetComponent(out InteractiveBase interactiveBase))
                {
                    interactiveBase.InteractiveStart(stateMachine);
                }
            }

            /*
            if (stateMachine.ReusableData.IsFishingState)
            {
                stateMachine.ReusableData.PlayerStatesData.PlayerFishingData.IsFishingSustain = true;
                stateMachine.ChangeState(stateMachine.CastingState);
                return;
            }

            if (stateMachine.ReusableData.IsCarryState)
            {
                stateMachine.ChangeState(stateMachine.CarryState);
                return;
            }

            if (stateMachine.ReusableData.IsAxeingState)
            {
                stateMachine.ChangeState(stateMachine.AxeState);
                return;
            }

            if (stateMachine.ReusableData.IsDiggingState)
            {
                if (IsPlayerDig()) stateMachine.ChangeState(stateMachine.DigState);
                return;
            }

            if (stateMachine.ReusableData.IsDoingState)
            {
                stateMachine.ChangeState(stateMachine.DoingState);
                return;
            }

            if (stateMachine.ReusableData.IsWateringState)
            {
                stateMachine.ChangeState(stateMachine.WateringState);
                return;
            }

            if (stateMachine.ReusableData.IsHammeringState)
            {
                stateMachine.ChangeState(stateMachine.HammeringState);
                return;
            }

            if (stateMachine.ReusableData.IsMiningState)
            {
                stateMachine.ChangeState(stateMachine.MiningState);
                return;
            }
            */
        }

        //攻击
        protected override void OnAttackStarted(InputAction.CallbackContext context)
        {
            base.OnAttackStarted(context);

            stateMachine.ChangeState(stateMachine.AttackState);
        }
        #endregion

        #region Main
        #endregion
    }
}
